$package('YiYa.merchant');
YiYa.merchant = function(){
	var _box = null;
	var _this = {
		openEditPriceRel:function(){
			_box.handler.edit(function(result){
				var url = '../merchant/loadMerchantList.do?type='+result.data.merchantType;
				$('#cc2').combobox('reload', url);
			});
		},
		config:{
			event:{
				view:function(){
					var selected = _box.utils.getCheckedRows();
					if ( _box.utils.checkSelectOne(selected)){
						var record = selected[0];
						_box.handler.view();
						var url = '../merchant/loadMerchantList.do?type='+record.merchant.type;
						$.get(url,function(data){
							$('#cc4').combobox('reload', url);
				        });
					}
				}
			},
			dataGrid:{
				title:'商家与商品价格列表',
				url:'dataList.do',
				columns:[[
				          {field:'id',checkbox:true},
				          {field:'product',title:'产品名称',width:120,
				        	  formatter:function(value,row,index){
				        		    var name = '';
									if(value!=null){
										name = value.name;
									}
									return name;
						  }},
						  {field:'code',title:'产品编号',width:80,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["product"]).code;
						  }},
						  {field:'color',title:'产品颜色',width:80,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["product"]).color;
						  }},
						  {field:'merchant',title:'商家',width:80,
				        	  formatter:function(value,row,index){
									var name = '';
									if(value!=null){
										name = value.name;
									}
									return name;
						  }},
						  {field:'merchant_type',title:'商家类型',width:80,
				        	  formatter:function(value,row,index){
				        		  var result = '';
				        		  if(new Object(row["merchant"]).type==1){
				        			  result = '供应商';
				        		  }else if(new Object(row["merchant"]).type==2){
				        			  result = '客户';
				        		  }
				        		  return result;
						  }},
				          {field:'pr.create_time',title:'创建时间',width:120,sortable:true,
				        	  formatter:function(value,row,index){
				        		  return row["createTime"];
						  }},
						  {field:'pr.update_time',title:'更新时间',width:120,sortable:true,
				        	  formatter:function(value,row,index){
				        		  return row["updateTime"];
						  }}
				          ]],
				          toolbar:[
				                   {id:'btnadd',text:'添加',btnType:'add'},
				                   {id:'btnedit',text:'编辑',btnType:'edit',handler:function(){
				                	_this.openEditPriceRel();   
				                   }},
				                   {id:'btndelete',text:'删除',btnType:'remove'},
				                   {id:'btnview',text:'查看',btnType:'view'}
				                   ]
			}
		},
		init:function(){
			$('.easyui-datebox').datebox({
			    formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();},
			    parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}
			});
			$('#cc1').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc2").combobox('clear');
			    }
			});
			$('#cc3').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc4").combobox('clear');
			    }
			});
			_box = new YDataGrid(_this.config);
			_box.init();
		}
	}
	return _this;
}();

$(function(){
	YiYa.merchant.init();
});


